import { HTTP } from '../utils/http';

let jsonData = `
 [
   {"id":"1", "goods_name": "24期分期/优惠350速发【新品】Huawei/华为 nova 5i手机官网官方旗舰店正品华为非", "price": "1200", "img_url":"https://g-search3.alicdn.com/img/bao/uploaded/i4/i1/1684634320/O1CN01zFzkD01hmbaTt9VwD_!!0-item_pic.jpg_580x580Q90.jpg_.webp"},
   {"id":"2", "goods_name": "24期分期/优惠350速发【新品】Huawei/华为 nova 5i手机官网官方旗舰店正品华为非", "price": "1200", "img_url":"https://g-search3.alicdn.com/img/bao/uploaded/i4/i1/1684634320/O1CN01zFzkD01hmbaTt9VwD_!!0-item_pic.jpg_580x580Q90.jpg_.webp"},
   {"id":"3", "goods_name": "24期分期/优惠350速发【新品】Huawei/华为 nova 5i手机官网官方旗舰店正品华为非", "price": "1200", "img_url":"https://g-search3.alicdn.com/img/bao/uploaded/i4/i1/1684634320/O1CN01zFzkD01hmbaTt9VwD_!!0-item_pic.jpg_580x580Q90.jpg_.webp"},
   {"id":"4", "goods_name": "24期分期/优惠350速发【新品】Huawei/华为 nova 5i手机官网官方旗舰店正品华为非", "price": "1200", "img_url":"https://g-search3.alicdn.com/img/bao/uploaded/i4/i1/1684634320/O1CN01zFzkD01hmbaTt9VwD_!!0-item_pic.jpg_580x580Q90.jpg_.webp"},
   {"id":"5", "goods_name": "24期分期/优惠350速发【新品】Huawei/华为 nova 5i手机官网官方旗舰店正品华为非", "price": "1200", "img_url":"https://g-search3.alicdn.com/img/bao/uploaded/i4/i1/1684634320/O1CN01zFzkD01hmbaTt9VwD_!!0-item_pic.jpg_580x580Q90.jpg_.webp"},
   {"id":"6", "goods_name": "24期分期/优惠350速发【新品】Huawei/华为 nova 5i手机官网官方旗舰店正品华为非", "price": "1200", "img_url":"https://g-search3.alicdn.com/img/bao/uploaded/i4/i1/1684634320/O1CN01zFzkD01hmbaTt9VwD_!!0-item_pic.jpg_580x580Q90.jpg_.webp"},
   {"id":"7", "goods_name": "24期分期/优惠350速发【新品】Huawei/华为 nova 5i手机官网官方旗舰店正品华为非", "price": "1200", "img_url":"https://g-search3.alicdn.com/img/bao/uploaded/i4/i1/1684634320/O1CN01zFzkD01hmbaTt9VwD_!!0-item_pic.jpg_580x580Q90.jpg_.webp"},
   {"id":"8", "goods_name": "24期分期/优惠350速发【新品】Huawei/华为 nova 5i手机官网官方旗舰店正品华为非", "price": "1200", "img_url":"https://g-search3.alicdn.com/img/bao/uploaded/i4/i1/1684634320/O1CN01zFzkD01hmbaTt9VwD_!!0-item_pic.jpg_580x580Q90.jpg_.webp"},
   {"id":"9", "goods_name": "24期分期/优惠350速发【新品】Huawei/华为 nova 5i手机官网官方旗舰店正品华为非", "price": "1200", "img_url":"https://g-search3.alicdn.com/img/bao/uploaded/i4/i1/1684634320/O1CN01zFzkD01hmbaTt9VwD_!!0-item_pic.jpg_580x580Q90.jpg_.webp"},
   {"id":"10", "goods_name": "24期分期/优惠350速发【新品】Huawei/华为 nova 5i手机官网官方旗舰店正品华为非", "price": "1200", "img_url":"https://g-search3.alicdn.com/img/bao/uploaded/i4/i1/1684634320/O1CN01zFzkD01hmbaTt9VwD_!!0-item_pic.jpg_580x580Q90.jpg_.webp"},
   {"id":"11", "goods_name": "24期分期/优惠350速发【新品】Huawei/华为 nova 5i手机官网官方旗舰店正品华为非", "price": "1200", "img_url":"https://g-search3.alicdn.com/img/bao/uploaded/i4/i1/1684634320/O1CN01zFzkD01hmbaTt9VwD_!!0-item_pic.jpg_580x580Q90.jpg_.webp"},
   {"id":"12", "goods_name": "24期分期/优惠350速发【新品】Huawei/华为 nova 5i手机官网官方旗舰店正品华为非", "price": "1200", "img_url":"https://g-search3.alicdn.com/img/bao/uploaded/i4/i1/1684634320/O1CN01zFzkD01hmbaTt9VwD_!!0-item_pic.jpg_580x580Q90.jpg_.webp"},
   {"id":"13", "goods_name": "24期分期/优惠350速发【新品】Huawei/华为 nova 5i手机官网官方旗舰店正品华为非", "price": "1200", "img_url":"https://g-search3.alicdn.com/img/bao/uploaded/i4/i1/1684634320/O1CN01zFzkD01hmbaTt9VwD_!!0-item_pic.jpg_580x580Q90.jpg_.webp"},
   {"id":"14", "goods_name": "24期分期/优惠350速发【新品】Huawei/华为 nova 5i手机官网官方旗舰店正品华为非", "price": "1200", "img_url":"https://g-search3.alicdn.com/img/bao/uploaded/i4/i1/1684634320/O1CN01zFzkD01hmbaTt9VwD_!!0-item_pic.jpg_580x580Q90.jpg_.webp"},
   {"id":"15", "goods_name": "24期分期/优惠350速发【新品】Huawei/华为 nova 5i手机官网官方旗舰店正品华为非", "price": "1200", "img_url":"https://g-search3.alicdn.com/img/bao/uploaded/i4/i1/1684634320/O1CN01zFzkD01hmbaTt9VwD_!!0-item_pic.jpg_580x580Q90.jpg_.webp"}

 ]
`;
let data = JSON.parse(jsonData);

class IndexModel extends HTTP {
  getGoodsList (tpl) {
    //use promise
    // return new Promise ((resolve, reject) => {
    //   this.ajax({
    //     url: 'Shopping_cart/getGoodsList',
    //     type: 'POST',
    //     dataType: 'JSON',
    //     success:  (data) => {
    //       console.log(data);
    //     }
    //   })
    // })
    return new Promise( (resolve, reject) => {
      let list = '';
      data.forEach((elem) => {
        list += tpl().replace(/{{(.*?)}}/g, (node, key) => {
          return {
            id: elem.id,
            img_url: elem.img_url,
            goods_name: elem.goods_name,
            price: elem.price
          }[key];
        })
      });
      resolve(list);
    })
  }
}

export { IndexModel };